﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace TweetMemeNET
{
    /// <summary>
    /// Represents a result set containing comments
    /// </summary>
    public class TweetMemeResultComments : TweetMemeResultBase, ITweetMemeResult
    {
        public TweetMemeResultComments(string xml)
            : base(xml)
        {
            
        }

        protected override void ParseResultXml()
        {
            Comments = new List<Comment>();

            XElement commentsElement = xml.Element(XName.Get("comments", string.Empty));

            if (commentsElement==null) // Check if there's a comments element (for URL-specific comments)
            {
                foreach (XElement comment in xml.Elements(XName.Get("comment", string.Empty)))
                {
                    Comments.Add(new Comment(comment));
                }
            }
            else // Retrieving firehose comments
            {
                foreach (XElement comment in commentsElement.Elements(XName.Get("comment", string.Empty)))
                {
                    Comments.Add(new Comment(comment));
                }
            }
        }

        /// <summary>
        /// Gets the list of TweetMeme comments
        /// </summary>
        public List<Comment> Comments { get; protected set; }
    }
}